package com.iwe3.protal.common;

import com.iwe3.protal.Enum.SystemEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 数据响应对象
 */

@Schema(description = "公共响应对象")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    @Schema(title = "code",
            description = "业务状态码",
            requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer code;//业务状态码

    @Schema(title = "msg",
            description = "状态码描述",
            requiredMode = Schema.RequiredMode.REQUIRED)
    private String msg;//状态码描述

    @Schema(title = "datas",
            description = "状态码描述",
            accessMode = Schema.AccessMode.READ_ONLY
    )
    private T datas;//返回给页面的数据

    public static R ok(){
        return new R(SystemEnum.OK.getCode(), SystemEnum.OK.getMsg(),null);
    }

    public static <E> R ok(E datas){
        return new R(SystemEnum.OK.getCode(), SystemEnum.OK.getMsg(),datas);
    }

    public static R fail(SystemEnum se){
        return new R(se.getCode(),se.getMsg(),null);
    }
}
